package com.googlecode.jerato.library.view.xml;

import java.io.IOException;
import java.io.Writer;
import java.util.Map;

import com.googlecode.jerato.library.SystemException;

public class XmlViewNodeValue extends XmlViewNode{

	protected String _valueName;
	
	public void render(Writer writer, Map map){
		if(_valueName == null){
			return;
		}

		Object valueObj = map.get(_valueName);
		if(valueObj == null){
			return;
		}
		String html = valueObj.toString();
		if(html == null){
			return;
		}
		html = html.replaceAll("&", "&amp;");
		html = html.replaceAll("<", "&lt;");
		html = html.replaceAll(">", "&gt;");
		html = html.replaceAll("\"", "&quot;");
		
		try{
			writer.write(html);
		}
		catch(IOException ioe){
			throw new SystemException("XmlView stream write failed.", ioe);
		}
	}

	public String getValueName() {
		return _valueName;
	}

	public void setValueName(String name) {
		_valueName = name;
	}
}
